package Exercise2;

import org.junit.Test;

import java.lang.reflect.Method;

public class ReflectionTest1 {
    @Test
    public void test1() throws ClassNotFoundException {
        Class clazz = Person.class;
        System.out.println(clazz);
        Person person = new Person();
        Class clazz2 = person.getClass();
        System.out.println(clazz2);
        Class person1 = Class.forName("JavaSenior\\Person");
        System.out.println(person1);
        ClassLoader classLoader = ReflectionTest1.class.getClassLoader();
        Class person2 = classLoader.loadClass("Person");
        System.out.println(person2);
    }
    @Test
    public void test2() throws Exception {
        Class<Person> cla = Person.class;
        Person p = cla.newInstance();
        Method eat = cla.getDeclaredMethod("eat");
        eat.setAccessible(true);
        eat.invoke(p);
    }
}
